<?php
	defined('_JEXEC') or die('Restricted access');
	require_once(CUTEENGINE_BASE_FIELD_PATH."base_field_class.php");
    
	//
    // t_field_grid
    //
	class t_field_grid extends t_base_field
	{
        
        // property declaration
		// private
        //B
       // private $body_script = '';
        //H
       // private $header_script = '';
        // E
        private $error_msg_tag = null;
		
        // N
        private $navigator_tag = null;
		
        // S
		public $special_columns_definition = array();
		
        const special_column_parameters_column_field_type = 0;
		const special_column_parameters_column_id = 1;
		const special_column_parameters_column_id_number = 2;
		const special_column_parameters_column_description = 3;
		const special_column_parameters_column_description_number = 4;
		const special_column_parameters_column_field_remaining_parameters = 5;
		const special_column_parameters_column_query = 6;
		const special_column_parameters_count = 7;
		//
		const special_column_type_hidden_column = 1;
		const special_column_type_no_edit_column = 2;
		const special_column_type_column_title_hide = 3;
		const special_column_type_column_url_parameter_value = 4;
		const special_column_type_last = 5;
		
        // T
		private $table_tag = null;
		private $type = '';
        // property declaration
		// protected
        
        // property declaration
		// public
        public $current_row = -1;
        // E
        const error_msg_tag_name = '%s_error_msg_tag_name'; 
		// G
		const language_position_reload = 1;
		const language_position_from = 2;
		const language_position_length = 3;
		const language_position_previous = 4;		
		const language_position_next = 5;
		const language_position_delete = 6;
		const language_position_insert = 7;
		const language_position_cancel = 8;
		const language_position_modify = 9;		
		const language_position_save = 10;		
		const language_position_question_on_delete = 11;		
		const language_position_multi_action_execute = 12;
		const language_position_question_on_execute = 13;
		const language_position_multi_action_none = 14;		
		const language_position_multi_action_all = 15;
		const language_position_multi_action_selected = 16;		
		const language_position_last = 17;
		// 
		public $multi_action_form_tag = null;
		public $multi_action_form_fields_tag = null;
		public $multi_action_form_options_tag = null;
		public $multi_action_form_options_btn_tag = null;
		public $multi_action_form_options_delete_btn_tag = null;
		// N
		public $no_reload_on_edit = true;
		// P
        const proper_properties_position_per_type = 1;
		const proper_properties_position_per_special_columns = 2;
		const proper_properties_position_per_multi_action_form = 3;
        const proper_properties_position_last = 4;
		// R
		const row_action_name_MUACT = 'MUACT'; 
		// S
		public $special_columns_array = array();

		const style_name_err = '%s_err';
		const style_name_loading = '%s_loading';
		const style_name_none = '%s_none';
		const style_name_ok = '%s_ok';
		const style_edit_panel_content = '%s_edit_panel_content';
        // T
        const tag_prefix_column = ":r:%s:c:%s:";
        const tag_prefix_row_cancel = ":r:%s:cancel";
		const tag_prefix_row_selected = ":r:%s:selected";
        const tag_prefix_row_edit = ":r:%s:edit";
		const tag_prefix_row_delete = ":r:%s:delete";
        const tag_prefix_row_insert = ":r:%s:insert";
        const tag_prefix_row_message = ":r:%s:message";
        const tag_prefix_row_save = ":r:%s:save";
        const tag_prefix_row = ":r:%s:";
		const tag_prefix_value_p1 = ":r:";
		const tag_prefix_value_p2 = ":c:";
		const tag_prefix_value_p3 = ":val";
		//const tag_prefix_value = self::tag_prefix_value_p1."%s".self::tag_prefix_value_p2."%s".self::tag_prefix_value_p3;
        const tag_prefix_value = ":r:%s:c:%s:val";
		const tag_prefix_value_edit_p1 = "__r__";
		const tag_prefix_value_edit_p2 = "__c__";
		const tag_prefix_value_edit_p3 = "__val";
        const tag_prefix_value_edit = "__r__%s__c__%s__val_ed";
		const tag_prefix_value_edit_header = "__r__%s__c__%s__val_ed_header";
        // method declaration
    	// private
		private function is_id_field_required($a_column_field_type)
		{
			return ($a_column_field_type == 't_field_lookup');
		}
		// protected
		
		// C
        protected function check_special_columns()
        {
            if (trim($this->proper_properties_array[self::proper_properties_position_per_special_columns]) == '')
            {
                throw new Exception('Error creating object class '.get_class($this).
                    " named: \"$this->name\". Required special columns were not specified (use '[]' for no special columns)");
				return false;
            }
            $this->special_columns_definition = json_decode($this->proper_properties_array[self::proper_properties_position_per_special_columns]);
            
            $local_return = count($this->special_columns_definition) == 0; 
			if (! $local_return)
				foreach($this->special_columns_definition as $local_special_column)
				{
					$local_return = (count((array)$local_special_column) == self::special_column_parameters_count);
					if (!$local_return)
					{
						throw new Exception('Error creating object class '.get_class($this).
							" named: \"$this->name\". Wrong required special column parameters number were specified");
						return false;
					}	
					else
					{
                        if (($this->is_id_field_required($local_special_column[self::special_column_parameters_column_field_type])) && 
							($local_special_column[self::special_column_parameters_column_id_number] >= $local_special_column[self::special_column_parameters_column_description_number]))				
						{	
							throw new Exception('Error creating object class '.get_class($this).
								" named: \"$this->name\". special_column_parameters_column_description_number must be major of special_column_parameters_column_id_number");
							return false;
						}
						else						
							return true;
					}
				}	
                
			return $local_return;
        } 	
        // G
		protected function get_call_back_actions_names()
		{
			$local_return = "[";
			foreach($this->parent_part->events as $loacl_type => $local_event)
				if ($local_return == "[")
					$local_return .= "\"".$this->parent_part->get_call_back_action_hashed_name($loacl_type)."\"";
				else
					$local_return .= ",\"".$this->parent_part->get_call_back_action_hashed_name($loacl_type)."\"";
			return $local_return."]"; 
			
		}

		protected function get_col_value($a_col_num)
		{
			$local_return = $a_col_num;
			if (array_key_exists($a_col_num,$this->special_columns_array))
			{
				$local_column = $this->special_columns_array[$a_col_num];
				//echo "a_col_num: $a_col_num - local_column[self::special_column_parameters_column_id_number]:".$local_column[self::special_column_parameters_column_id_number]."<br>";
				if ((! $this->is_id_field_required($local_column[self::special_column_parameters_column_field_type])) || 
					($local_column[self::special_column_parameters_column_id_number] != $a_col_num))
				{
					//echo "a_col_num:$a_col_num <br>";
					$local_return = $local_column[self::special_column_parameters_column_description];
				}	
			}
			return $local_return;
		}
		
        
		protected function get_row_message_script($a_row,$a_style_message)
        {
            $local_href = "''";
            if ($a_style_message == self::style_name_err)
                $local_href = "'#' + this.error_msg_tag_name";
            return "var local_msg_tag = this.set_row_class_name('".self::tag_prefix_row_message."',this.get_tag_name('$a_style_message','',[this.name]),".$a_row."); ".
        "if (local_msg_tag) local_msg_tag.parentNode.href = $local_href;";
        }
		//gets html code to fire event type action on html element
		protected function get_field_event_call($a_event_type,$a_argouments)
        {			
			//echo "a_event_type:$a_event_type<BR>";
			$local_return = '';
			$local_event = $this->events[$a_event_type];
			
			switch ($local_event->event_type) 
            {
                case t_base_field::field_event_type_on_selected:
                case t_base_field::field_event_type_on_edit:
                case t_base_field::field_event_type_on_cancel:
                case t_base_field::field_event_type_on_save:
				case t_base_field::field_event_type_on_insert:
                case t_base_field::field_event_type_on_reload:
				case t_base_field::field_event_type_on_delete:
                case t_base_field::field_event_type_on_paging:
					$local_return = t_cuteengine::javascript_instance_name.".".$this->name.".".$local_event->event_name."($a_argouments)";
				break;                
			}
			return $local_return;
		}
		//gets html code to fire event type action on html element
		protected function get_field_event_script($a_event_type,$a_argouments)
        {			
			//echo "a_event_type:$a_event_type<BR>";
			$local_return = '';
			$local_event = $this->events[$a_event_type];
			
			switch ($local_event->event_type) 
            {
                case t_base_field::field_event_type_on_selected:
                case t_base_field::field_event_type_on_edit:
                case t_base_field::field_event_type_on_cancel:
                case t_base_field::field_event_type_on_save:
				case t_base_field::field_event_type_on_insert:
                case t_base_field::field_event_type_on_reload:
				case t_base_field::field_event_type_on_delete:
                case t_base_field::field_event_type_on_paging:
					$local_return = "onclick=\"".$this->get_field_event_call($a_event_type,$a_argouments)."\"";
				break;                
			}
			return $local_return;
		}
		protected function get_javascript_events_list_initialization()
		{
			global $g_javascript_namespace;
			foreach($this->parent_part->events as $loacl_type => $local_event)
				$g_javascript_namespace->header_script_generator->add_property_to_a_class(
					get_class($this),"events_list[".$loacl_type."]","a_events_array[(".$loacl_type."-1)]",false);
		}
        static function get_help_proper_property($a_index)
		{
			$local_return = 'NO HELP AVAILABLE';
			/*switch ($a_index) 
            {
                case self::proper_properties_position_:
					$local_return = '';
				break;                
			}*/
			return $local_return;
		}
        static function get_default_proper_property($a_index)
		{
			$local_return = '';
			//echo "a_index: $a_index<br>";
			switch ($a_index) 
            {
				case self::proper_properties_position_per_type:
					$local_return = 'grid';
				break;
 				case self::proper_properties_position_per_special_columns:
					$local_return = '[]';
				break;
                case self::proper_properties_position_per_multi_action_form:
					$local_return = 'FALSE';
				break;                
			}
			return $local_return;
		}
		protected function get_proper_properties_position_last()
        {
            return self::proper_properties_position_last;
        }
		protected function get_special_column_field($a_row,$a_name)
        {
            return $this->get_tag_name(self::tag_prefix_value_edit,array($a_row,$a_name));
        }
		protected function get_special_columns_js_array()
        {
            $local_result = '[';
			$local_start_index = 0;//print_r($this->special_columns_array );
            foreach($this->special_columns_array as $local_index => $local_column)
            {
				for($local_empty_index = $local_start_index; $local_empty_index < $local_index; $local_empty_index++)
				{
					if ($local_result == '[')
						$local_result .= "$local_empty_index";
					else
						$local_result .= ",$local_empty_index";
				}
				//
				if (($this->is_id_field_required($local_column[self::special_column_parameters_column_field_type])) && 
					($local_column[self::special_column_parameters_column_id_number] == $local_index))
					if ($local_result == '[')
						$local_result .= "$local_empty_index";
					else
						$local_result .= ",$local_empty_index";
				else if ($local_result == '[')
                    $local_result .= '["'.$local_column[self::special_column_parameters_column_description].'","'.$local_column[self::special_column_parameters_column_id_number].'"]';
                else
                    $local_result .= ',["'.$local_column[self::special_column_parameters_column_description].'","'.$local_column[self::special_column_parameters_column_id_number].'"]';
				//echo $local_column[self::special_column_parameters_column_description].'","'.$local_column[self::special_column_parameters_column_id_number];
				//	
				$local_start_index = $local_index + 1;	
			}
            return $local_result.']';
        }
		public function get_special_column_type_column_url_parameter_value($a_column_no)
		{
			global $g_url_parameters_namespace;
			
			$local_return = '';
			$local_param_index = $this->get_special_column_type_parameter_value($a_column_no,0);
			//echo "local_param_index: $local_param_index<br>";
			$local_arg_index = $this->get_special_column_type_parameter_value($a_column_no,1);
			//echo "local_arg_index: $local_arg_index<br>";			
			$local_parameter = $g_url_parameters_namespace->get_parameter_by_position($local_param_index); 
			if (isset($local_parameter))
				$local_return = $local_parameter->get_argument_value ($local_arg_index);
			return $local_return;
		}
		public function get_special_column_type_parameter_value($a_column_no,$a_parameter_index)
		{
			
			$local_value = '';
			$local_special_column = $this->special_columns_array[$a_column_no];
			if (isset($local_special_column))
			{
				//print_r($local_special_column[self::special_column_parameters_column_field_remaining_parameters]);
				$local_param_index_present = ($a_parameter_index < count($local_special_column[self::special_column_parameters_column_field_remaining_parameters]));
				switch ($local_special_column[self::special_column_parameters_column_field_type]) 
				{
					case self::special_column_type_column_url_parameter_value:
						switch ($a_parameter_index) 
						{
							/* parameter index */
							case 0:
								
								if ($local_param_index_present)
								{
									$local_value = $local_special_column[self::special_column_parameters_column_field_remaining_parameters][$a_parameter_index];
								}
								else
								{
									$local_value = '0';
								}
								//echo "local_value: $local_value<br>";
							break;
							/* argument of parameter index */
							case 1:
								if ($local_param_index_present)
								{
									$local_value = $local_special_column[self::special_column_parameters_column_field_remaining_parameters][$a_parameter_index];
								}
								else
								{
									$local_value = '0';
								}
							break;
							/* visible */
							case 2:
								if ($local_param_index_present)
								{
									$local_value = $local_special_column[self::special_column_parameters_column_field_remaining_parameters][$a_parameter_index];
								}
								else
								{
									$local_value = 'FALSE';
								}
							break;

						}
						
						
						
					break;
				}
			
			}
			return $local_value;
			
		}
        // method declaration
    	// public
        public function __construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str)
		{
            global $g_ambient_namespace;
			parent::__construct($a_parent_part,$a_common_properties_str, $a_proper_properties_str);
            //echo "this->proper_properties_array[self::proper_properties_position_per_special_columns]: ".$this->proper_properties_array[self::proper_properties_position_per_special_columns]."<br>";
            $local_file_name = CUTEENGINE_CUSTOM_LANGUAGES_PATH.$g_ambient_namespace->language.DIRECTORY_SEPARATOR.$this->name."_lang.php";
            //echo "local_file_name: $local_file_name<br>";
			// LANGUAGES
            if (file_exists($local_file_name))
                $g_ambient_namespace->load_custom_language($this,$this->name);
			$this->check_special_columns();
					
			foreach($this->special_columns_definition as $local_column_definition)
			{
				if (($local_column_definition[self::special_column_parameters_column_field_type] == self::special_column_type_hidden_column) ||
					($local_column_definition[self::special_column_parameters_column_field_type] == self::special_column_type_no_edit_column)||
					($local_column_definition[self::special_column_parameters_column_field_type] == self::special_column_type_column_title_hide)||
					($local_column_definition[self::special_column_parameters_column_field_type] == self::special_column_type_column_url_parameter_value))
				{
					//print_r($local_column_definition);
					$this->special_columns_array[$local_column_definition[self::special_column_parameters_column_description_number]] = $local_column_definition;
				}
				else
				{
					if ($this->is_id_field_required($local_column_definition[self::special_column_parameters_column_field_type]))
						$this->special_columns_array[$local_column_definition[self::special_column_parameters_column_id_number]] = $local_column_definition;
					//echo "local_column_definition: $local_column_definition";
					$this->special_columns_array[$local_column_definition[self::special_column_parameters_column_description_number]] = $local_column_definition;
					//echo 'this->get_special_column_field(\'all\',$local_column_definition[self::special_column_parameters_column_description]): '. $this->get_special_column_field('all',$local_column_definition[self::special_column_parameters_column_description]).'<br>';
					$local_remaining_parameters = "|".implode("|",$local_column_definition[self::special_column_parameters_column_field_remaining_parameters])."|";
					if ($local_column_definition[self::special_column_parameters_column_field_type] == 't_field_lookup')
					{
						$this->parent_part->add_field_uses_as_included("|".$local_column_definition[self::special_column_parameters_column_field_type]."|". $this->get_special_column_field('all',$local_column_definition[self::special_column_parameters_column_description]).$local_remaining_parameters); //"|-1|0||false|");
						$this->parent_part->add_action_for_field_uses_as_included('["none","t_action_list_from_db","get_'.$this->get_special_column_field('all',$local_column_definition[self::special_column_parameters_column_description]).'",["'.$this->get_special_column_field('all',$local_column_definition[self::special_column_parameters_column_description]).'","","'.$this->get_special_column_field('all',$local_column_definition[self::special_column_parameters_column_description]).'",""],"'.$local_column_definition[self::special_column_parameters_column_query].'"]');
					}
					else
					{
						$this->parent_part->add_field_uses_as_included("|".$local_column_definition[self::special_column_parameters_column_field_type]."|". $this->get_special_column_field('all',$local_column_definition[self::special_column_parameters_column_description]).$local_remaining_parameters); //"|-1|0||");
					}
				}
			}
			$this->type = $this->proper_properties_array[self::proper_properties_position_per_type];
			
			
		}

        // C
		public function create_javascript_initialization_component()
		{
            global $g_javascript_namespace;
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this), "class_name_row_none","this.get_tag_name('".self::style_name_none."','',[this.name])"); 
				
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this), "class_name_row_ok","this.get_tag_name('".self::style_name_ok."','',[this.name])"); 
				
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this), "class_name_row_loading", "this.get_tag_name('".self::style_name_loading."','',[this.name])"); 
				
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this), "class_name_row_err","this.get_tag_name('".self::style_name_err."','',[this.name])"); 
			//E
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
				get_class($this), "error_msg_tag_name","this.get_tag_name('".self::error_msg_tag_name."','',[this.name])"); 

			//field method
			// A
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),"set_row_class_name",'a_prefix,a_class_name,a_row',"
	if (isNaN(a_row) == true)
    {
        var local_tag = document.getElementById(this.get_tag_name(a_prefix,'',[a_row]));
        set_tag_property(['className'],[a_class_name],local_tag,false);
    }
    else
    {
        var local_row = parseInt(a_row);
        var local_stop_row = local_row+1;
        if (local_row < 0)
        {
            local_row = 0;
            local_stop_row = -1;
        }    
        var local_exit = false;
        var local_tag = null;
        var local_old_tag = null;
        var local_current_class = '';
        while ((!local_exit) && ((local_stop_row == -1) || (local_row < local_stop_row)))
        {
            local_tag = document.getElementById(this.get_tag_name(a_prefix,'',[local_row]));
            local_exit = (local_tag == null);
            if ((!local_exit))
            {
                local_current_class = local_tag['className'];
                if ((local_current_class != a_class_name) &&
                    ((a_prefix != '".self::tag_prefix_row_message."') || (a_class_name != this.class_name_row_none) || ( local_current_class != this.class_name_row_loading)))
                    (set_tag_property(['className'],[a_class_name],local_tag,false) );
                
            }	
            if (local_tag != null)
                local_old_tag = local_tag;
            local_row ++;
        }
        local_tag = local_old_tag;
    }
    return local_tag;
    "); 
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                        get_class($this),'clear_err_msg',''," 
    this.html_tag(this.error_msg_tag_name).innerHTML = ''; 
    set_tag_style_property(['display'],['none'],this.error_msg_tag_name,true);
	") ;
	// E
                $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                        get_class($this),'edit_row_activation','a_active,a_copy_value,a_row'," 
    var local_value_style = '';
	var local_edit_value_style = 'none';
	if (a_active == true)
	{
		local_value_style = 'none';
		local_edit_value_style = '';
        set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_cancel."','',[a_row]),true);
		set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_save."','',[a_row]),true);	
        set_tag_style_property(['display'],['none'],this.get_tag_name('".self::tag_prefix_row_insert."','',[a_row]),(a_row != 'ins'));
		set_tag_style_property(['display'],['none'],this.get_tag_name('".self::tag_prefix_row_edit."','',[a_row]),(a_row != 'ins'));	
        set_tag_style_property(['display'],['none'],this.get_tag_name('".self::tag_prefix_row_delete."','',[a_row]),(a_row != 'ins'));
	}
    else
    {
        set_tag_style_property(['display'],['none'],this.get_tag_name('".self::tag_prefix_row_cancel."','',[a_row]),true);
		set_tag_style_property(['display'],['none'],this.get_tag_name('".self::tag_prefix_row_save."','',[a_row]),true);	
        set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_insert."','',[a_row]),(a_row != 'ins'));
		set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_edit."','',[a_row]),(a_row != 'ins'));	
        set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_delete."','',[a_row]),(a_row != 'ins'));
    }
    
	var local_col_num=0;
	var local_col=this.get_col_value(local_col_num);
	var local_exit = false;
	while (!local_exit)
	{
        var local_ce = ".t_cuteengine::javascript_instance_name."[this.get_tag_name('".self::tag_prefix_value_edit."','',['all',local_col])]; 
		if ((local_ce != undefined) && (local_ce.edit_row_activation != undefined))
        {
            local_ce.edit_row_activation(this.get_tag_name('".self::tag_prefix_value."','',[a_row,local_col]),
                this.get_tag_name('".self::tag_prefix_value_edit."','',[a_row,local_col]),a_active,a_copy_value);
			set_tag_style_property(['display'],[local_edit_value_style],this.get_tag_name('".self::tag_prefix_value_edit_header."','',[a_row,local_col]),false);	
        }
        else
        {
            if (local_ce != undefined)
            {
                var local_msg_tag = set_tag_property(['innerHTML'],[''],this.get_tag_name('".self::tag_prefix_value_edit."','',[a_row,local_col])+'".t_field_text::postfix_message_tag_name."',true);
                set_tag_style_property(['display'],[local_edit_value_style],local_msg_tag,false);
				
                
            }

            var local_value = document.getElementById(this.get_tag_name('".self::tag_prefix_value."','',[a_row,local_col]));
			if (local_value)
			{
				set_tag_style_property(['display'],[local_value_style],local_value,true);
			}

			var local_edit_value = set_tag_style_property(['display'],[local_edit_value_style],this.get_tag_name('".self::tag_prefix_value_edit."','',[a_row,local_col]),false);
			if (local_edit_value)
			{
				var lh = get_height_value(local_edit_value,'px',-10);
				var lcurr_h = parseInt(lh);
				if (parseInt(lh) < 27)
					lh= '27px';
				var lw = get_width_value(local_edit_value,'px',-10);
				var lcurr_w = parseInt(lw);
				if (parseInt(lw) <= 10)
					lw = get_width_value(local_edit_value.parentNode,'px',-10);
				
			}
			else
			{
				var lh = 0;
				var lw = 0;
				var lcurr_h = 0;
				var lcurr_w = 0;
			}
			
			
			set_tag_style_property(['display'],[local_edit_value_style],this.get_tag_name('".self::tag_prefix_value_edit_header."','',[a_row,local_col]),false);
			local_exit = ((local_value == null) || (local_edit_value == null));
			if ((!local_exit) && (a_copy_value))
			{
				if (a_active == true)
				{
					if ((local_edit_value.tagName == 'INPUT') && (local_edit_value.type == 'checkbox'))
						local_edit_value.checked = local_value.checked;
					else
						local_edit_value.value = local_value.innerHTML;
					if (lcurr_h < 27)
						local_edit_value.style.height = lh;
					if (lcurr_w < 27)	
						local_edit_value.style.width = lw;

				} 
				else
				{
					if ((local_edit_value.tagName == 'INPUT') && (local_edit_value.type == 'checkbox'))
						local_value.checked = local_edit_value.checked;
					else
						local_value.innerHTML = local_edit_value.value;
				} 

			}		
		}

        local_col_num ++;
		local_col=this.get_col_value(local_col_num);
	}
	") ;
	// E			
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                        get_class($this),'_m_a_o_options_changed','radio'," 
	if (radio.value == 'none')
	{
		set_tag_style_property(['display'],['none'],'".$this->multi_action_form_fields_tag->name."' ,true);
		set_tag_style_property(['display'],['none'],'".$this->multi_action_form_options_btn_tag->name."' ,true);
		set_tag_style_property(['display'],['none'],'".$this->multi_action_form_options_delete_btn_tag->name."' ,true);
	}
	else
	{	
		set_tag_style_property(['display'],[''],'".$this->multi_action_form_fields_tag->name."' ,true);
		set_tag_style_property(['display'],[''],'".$this->multi_action_form_options_btn_tag->name."' ,true);
		set_tag_style_property(['display'],[''],'".$this->multi_action_form_options_delete_btn_tag->name."' ,true);
	}
	
    ") ; 
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                        get_class($this),'enable_field_edit','event,a_row,a_col_number'," 
    var local_target = event.target ? event.target : event.srcElement;
	var local_ce = ".t_cuteengine::javascript_instance_name."[this.get_tag_name('".self::tag_prefix_value_edit."','',['all',a_col_number])]; 
	if ((local_ce != undefined) && (local_ce.edit_row_activation != undefined))
	{
		local_ce.edit_row_activation(this.get_tag_name('".self::tag_prefix_value."','',[a_row,a_col_number]),
			this.get_tag_name('".self::tag_prefix_value_edit."','',[a_row,a_col_number]),local_target.checked,false);
		
	}
	else
	{
		var local_Sibling = local_target.nextSibling;
		while (local_Sibling)
		{
			if ((local_Sibling.tagName == 'INPUT') || (local_Sibling.tagName == 'BUTTON') || (local_Sibling.tagName == 'DIV'))
			{
				if (local_target.checked)
				{
					set_tag_style_property(['display'],[''],local_Sibling ,true);
				}
				else
				{	
					set_tag_style_property(['display'],['none'],local_Sibling ,true);
				}
				
			}
			local_Sibling = local_Sibling.nextSibling;
			
		}
	}
	
    ") ; 
            $g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                        get_class($this),'get_col_value','a_col_number'," 
    var local_col = this.special_columns_array[a_col_number];
	if ((typeof local_col != 'undefined') && (local_col != a_col_number))
	{
		local_col = local_col[0];
	}
	else
		local_col = a_col_number;
	return local_col;
    ") ;      
			$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
                        get_class($this),'get_row_number_by_name','a_name'," 
	var lstart = a_name.indexOf('".self::tag_prefix_value_p1."') + '".self::tag_prefix_value_p1."'.length;
	var llen = a_name.indexOf('".self::tag_prefix_value_p2."') - lstart;
	if ((lstart > -1) && (llen > 0))
		return a_name.substr(lstart,llen);	
		
	var lstart = a_name.indexOf('".self::tag_prefix_value_edit_p1."') + '".self::tag_prefix_value_edit_p1."'.length;
	var llen = a_name.indexOf('".self::tag_prefix_value_edit_p2."') - lstart;
	if ((lstart > -1) && (llen > 0))
		return a_name.substr(lstart,llen);
	return -1;
    ") ;    	
		}    
		public function create_tags_structure()
        {
            //echo __METHOD__."<BR>";
            global $g_ambient_namespace;
            global $g_javascript_namespace;
			parent::create_tags_structure(
                // ARGUMENTS DECLARATIONS
                "a_special_columns_array",
                // ARGUMENTS VALUES
                "'".$this->get_special_columns_js_array()."'");
            // Properties
            // S
			$g_javascript_namespace->header_script_generator->add_property_to_a_class(
                get_class($this),'special_columns_array',"a_special_columns_array",false);
			// methodd

			// component
			$local_name = $this->common_properties_array[t_base_field::common_properties_position_per_field_name];
			//echo "local_name: $local_name<br>";
            $local_current_tag = parent::add_tag(t_base_tag_type::btt_div,
                $local_name);
            $this->main_tag = $local_current_tag;
			$this->main_tag->include_child_str = false;
            $this->default_start_tag = $this->main_tag;
            $this->default_result_tag = $this->main_tag;
			//

			$this->error_msg_tag = $this->main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,$this->get_tag_name(self::error_msg_tag_name,array($this->name)));
            $this->error_msg_tag->add_style_property('display','none');
			//
            $this->navigator_tag = $this->main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,
				$this->main_tag->name."_nav");
            $this->navigator_tag->include_child_str = false;
            //
			if ($this->is_multi_action_form_active() )
			{
				$this->multi_action_form_tag = $this->main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,
					$this->main_tag->name."_multi_action_form");
				$this->multi_action_form_tag->class_name = "multi_action_form_tag_class";
				$this->add_style_sheet_property(".multi_action_form_tag_class","background-color","lightgray");
				$this->add_style_sheet_property(".multi_action_form_tag_class","margin","20px");
				$this->add_style_sheet_property(".multi_action_form_tag_class","padding","20px");
				$this->add_style_sheet_property(".multi_action_form_tag_class button","padding","5px");
				$this->add_style_sheet_property(".multi_action_form_tag_class button","margin-left","5px");

				$this->multi_action_form_tag->include_child_str = false;
				// options
				$this->multi_action_form_options_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,
					$this->main_tag->name."_multi_action_options");
				$this->multi_action_form_options_tag->include_child_str = false;
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_label,
					$this->main_tag->name."_m_a_o_lbl");
				$local_current_tag->set_text_to_include('Azioni multiple:');
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_radiobutton,
					$this->main_tag->name."_m_a_o_none");
				$local_current_tag->add_property('checked','checked');
				$local_current_tag->add_property('value','none');
				$local_current_tag->add_property('name','_m_a_o_options');
				$local_current_tag->add_property('onclick',t_cuteengine::javascript_instance_name.".".$this->name."._m_a_o_options_changed(this)");
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_label,
					$this->main_tag->name."_m_a_o_none_lbl");
				$local_current_tag->add_property('for',$this->main_tag->name."_m_a_o_none");
				$local_current_tag->set_text_to_include($this->lang[t_field_grid::language_position_multi_action_none]);
				//
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_radiobutton,
					$this->main_tag->name."_m_a_o_all");
				$local_current_tag->add_property('value','all');
				$local_current_tag->add_property('name','_m_a_o_options');
				$local_current_tag->add_property('onclick',t_cuteengine::javascript_instance_name.".".$this->name."._m_a_o_options_changed(this)");
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_label,
					$this->main_tag->name."_m_a_o_all_lbl");
				$local_current_tag->add_property('for',$this->main_tag->name."_m_a_o_all");
				$local_current_tag->set_text_to_include($this->lang[t_field_grid::language_position_multi_action_all]);
				//
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_radiobutton,
					$this->main_tag->name."_m_a_o_sel");
				$local_current_tag->add_property('value','sel');
				$local_current_tag->add_property('name','_m_a_o_options');
				$local_current_tag->add_property('onclick',t_cuteengine::javascript_instance_name.".".$this->name."._m_a_o_options_changed(this)");
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_label,
					$this->main_tag->name."_m_a_o_sel_lbl");
				$local_current_tag->add_property('for',$this->main_tag->name."_m_a_o_sel");
				$local_current_tag->set_text_to_include($this->lang[t_field_grid::language_position_multi_action_selected]);
				// button
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_button,
					$this->main_tag->name."_m_a_o_btn");
				$local_current_tag->set_text_to_include($this->lang[t_field_grid::language_position_multi_action_execute]);
				$this->multi_action_form_options_btn_tag = $local_current_tag;
				$this->multi_action_form_options_btn_tag->add_style_property('display','none');
				$local_current_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_button,
					$this->main_tag->name."_m_a_o_delete_btn");
				$local_current_tag->set_text_to_include($this->lang[t_field_grid::language_position_delete]);
				$this->multi_action_form_options_delete_btn_tag = $local_current_tag;
				$this->multi_action_form_options_delete_btn_tag->add_style_property('display','none');
				// fields
				$this->multi_action_form_fields_tag = $this->multi_action_form_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_div,
					$this->main_tag->name."_multi_action_fields");
				$this->multi_action_form_fields_tag->include_child_str = false;
				$this->multi_action_form_fields_tag->add_style_property('display','none');
				

			}
            // error_msg_tag_name
			$this->table_tag = $this->main_tag->create_and_add_child_at_bottom(t_base_tag_type::btt_table,
				$local_name."_table");
            $this->table_tag->include_child_str = false;		

			//columns style
			$this->add_style_sheet_property(".".$this->name."edit_col","vertical-align","middle");
			$this->add_style_sheet_property(".".$this->name."_event_type_on_selected","vertical-align","middle");
			$this->add_style_sheet_property(".".$this->name."_event_type_on_selected_checked","vertical-align","middle");
			$this->add_style_sheet_property(".".$this->name."_event_type_on_selected_checked","background-color","orange");
			$this->add_style_sheet_property(".".$this->name."value_col","vertical-align","middle");
			$this->add_style_sheet_property(".".$this->name."value_col","padding-right","10px");
			// ICON STYLE
			//echo"this->default_result_tag->name:".$this->default_result_tag->name."<br>";
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_err,array($this->name)),"background","url(\"".$g_ambient_namespace->get_absolute_web_style_file_path()."err.png\") no-repeat scroll center center");
            //$this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_err,array($this->name)),"display","compact");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_err,array($this->name)),"min-height","35px");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_err,array($this->name)),"min-width","35px");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_ok,array($this->name)),"background","url(\"".$g_ambient_namespace->get_absolute_web_style_file_path()."ok.png\") no-repeat scroll center center");
            //$this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_ok,array($this->name)),"display","compact");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_ok,array($this->name)),"min-height","35px");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_ok,array($this->name)),"min-width","35px");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_none,array($this->name)),"background",""/*"url(\"".$g_ambient_namespace->get_absolute_web_style_file_path()."none.png\") no-repeat scroll center center"*/);
            //$this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_none,array($this->name)),"display","compact");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_none,array($this->name)),"min-height","35px");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_none,array($this->name)),"min-width","35px");
			$this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_loading,array($this->name)),"background","url(\"".$g_ambient_namespace->get_absolute_web_style_file_path()."loading.gif\") no-repeat scroll center center");
            //$this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_loading,array($this->name)),"display","compact");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_loading,array($this->name)),"min-height","35px");
            $this->add_style_sheet_property(".".$this->get_tag_name(self::style_name_loading,array($this->name)),"min-width","35px");
			// multi action style
			//$this->add_style_sheet_property($this->name."_filter_div_class","min-width","35px");
        }
        // F
		public function finalize_creation_field()
        {
			
            global $g_cuteengine;
			parent::finalize_creation_field();
			if ($this->is_multi_action_form_active() )
			{
				$this->multi_action_form_options_btn_tag->add_property('onclick', $this->get_field_event_call(t_base_field::field_event_type_on_save,"event,'".self::row_action_name_MUACT."'"));
				$this->multi_action_form_options_delete_btn_tag->add_property('onclick', $this->get_field_event_call(t_base_field::field_event_type_on_delete,"event,'".self::row_action_name_MUACT."'"));				
			}
		}	
		// G

		public function get_navigator_tags_structure($a_from,$a_length)
        {
        	//echo "PIPPO<br>";
			$local_result = '';
            if ($this->is_event_able(t_base_field::field_event_type_on_reload))
			{
                $local_result .= "<a id=\"". $this->name ."_reload\" href=\"#". $this->name ."_reload\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_reload,t_base_field::field_event_type_on_reload.",'reload',window.cuteengine.html_tag('". $this->name ."_paging_from'),window.cuteengine.html_tag('". $this->name ."_paging_length')").">".$this->lang[self::language_position_reload]."</span></a>";
			}
            if ($this->is_event_able(t_base_field::field_event_type_on_insert))
			{
                $local_result .= "<a id=\"". $this->get_tag_name(self::tag_prefix_row_insert,array('nav')) ."\" href=\"#".$this->get_tag_name(self::tag_prefix_row,array('ins'))."\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_insert,"event,'ins'").">".$this->lang[self::language_position_insert]."</span></a>";
			}
            if ($this->is_event_able(t_base_field::field_event_type_on_paging))
			{
                //echo "CIAO<br>";
				$local_result .= "<div id=\"". $this->name ."_paging\">".$this->lang[self::language_position_from]."<input id=\"". $this->name ."_paging_from\" value=\"$a_from\"></input>".$this->lang[self::language_position_length]."<input id=\"". $this->name ."_paging_length\" value=\"$a_length\"></input>".
				"<a id=\"". $this->name ."_previous\" href=\"#". $this->name ."_previous\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_paging,t_base_field::field_event_type_on_paging.",'previous',window.cuteengine.html_tag('". $this->name ."_paging_from'),window.cuteengine.html_tag('". $this->name ."_paging_length')").">".$this->lang[self::language_position_previous]."</span></a>".
				"<a id=\"". $this->name ."_next\" href=\"#". $this->name ."_next\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_paging,t_base_field::field_event_type_on_paging.",'next',window.cuteengine.html_tag('". $this->name ."_paging_from'),window.cuteengine.html_tag('". $this->name ."_paging_length')").">".$this->lang[self::language_position_next]."</span></a></div>";
				
			}            
            return $local_result;
        }
		
		public function get_event_html_body_script($a_event_type,$a_query_parameter,$a_current_field_no,$a_current_row_no)
        {
			$local_result = '';
			if ($this->is_event_able($a_event_type))
			{
				$local_row_name = $this->get_tag_name(t_field_grid::tag_prefix_row,array($a_current_row_no));
				switch ($a_event_type) 
				{
					case t_base_field::field_event_type_on_selected:
						$local_result = "<td align=\"center\" class=\"".$this->name."_event_type_on_selected\"><input id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_selected,array($a_current_row_no)) ."\" type=\"checkbox\" value=\"enabled\" ".$this->get_field_event_script(t_base_field::field_event_type_on_selected,"event,'".$a_query_parameter->sql_values[$a_current_field_no]."'")."/></td>";
						
					break;				

					case t_base_field::field_event_type_on_edit:
						$local_result = "<td align=\"center\"  class=\"".$this->name."edit_col\"><a id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_edit,array($a_current_row_no)) ."\" href=\"#$local_row_name\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_edit,"event,'$a_current_row_no'").">".$this->lang[t_field_grid::language_position_modify]."</span></a></td>";

					break;
					
					case t_base_field::field_event_type_on_cancel:
						$local_result = "<td align=\"center\"  class=\"".$this->name."edit_col\"><a style=\"display: none\" id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_cancel,array($a_current_row_no)) ."\" href=\"#$local_row_name\" class=\"".$this->name."edit_col\"><span ".$this->get_field_event_script(t_base_field::field_event_type_on_cancel,"event,'$a_current_row_no',true").">".$this->lang[t_field_grid::language_position_cancel]."</span></a></td>";
					break;
					
					case t_base_field::field_event_type_on_save:
						$local_result = "<td align=\"center\"  class=\"".$this->name."edit_col\"><a style=\"display: none\" id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_save,array($a_current_row_no)) ."\" href=\"#$local_row_name\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_save,"event,'$a_current_row_no'").">".$this->lang[t_field_grid::language_position_save]."</span></a></td>";
					
					break;
					
					case t_base_field::field_event_type_on_insert:
						$local_result = "<td align=\"center\"  class=\"".$this->name."edit_col\"><a id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_insert,array($a_current_row_no)) ."\" href=\"#".$this->get_tag_name(t_field_grid::tag_prefix_row,array('ins'))."\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_insert,"event,'ins'").">".$this->lang[t_field_grid::language_position_insert]."</span></a></td>";
					break;
					
					case t_base_field::field_event_type_on_delete:
						$local_result = "<td align=\"center\"  class=\"".$this->name."edit_col\"><a id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_delete,array($a_current_row_no)) ."\" href=\"#$local_row_name\" ><span ".$this->get_field_event_script(t_base_field::field_event_type_on_delete,"event,'$a_current_row_no'").">".$this->lang[t_field_grid::language_position_delete]."</span></a></td>";
					break;
				}
			}	

			return $local_result;
        }		
		
		public function get_language_position_last()
        {
            return self::language_position_last;
        }
		// gets result script for action based on event type
        public function get_result_action_script($a_event_type,$parent_event_type,
            $a_row,$a_content_loader_result)
		{
			if (is_numeric($a_row) || (($a_row[0] != "'") && ($a_row[0] != '"')))
				$a_row = "'$a_row'";
			//echo "a_row: $a_row<br>";	
			//echo "a_event_type: $a_event_type<br>";
            $local_error_msg = '';
			$local_event = $this->events[$a_event_type];
			//$local_cancel_event = $this->events[t_base_field::field_event_type_on_cancel];
			$local_reload_event = $this->events[t_base_field::field_event_type_on_reload];
			if ($a_content_loader_result->succeeded)
			{
				
			}	
			else
			{
                
				$local_error_msg = "this.html_tag('".$this->get_tag_name(self::error_msg_tag_name,array($this->name))."').innerHTML = '".addslashes($a_content_loader_result->error_msg)."';".
					"var local_tag = set_tag_style_property(['display'],[''],'".$this->get_tag_name(self::error_msg_tag_name,array($this->name))."',true);".
					"local_tag.onclick = this.clear_err_msg.set_scope(this);";
			}	
			switch ($a_event_type) 
            {
                /***********  t_base_field::field_event_type_on_save ***********/
                case t_base_field::field_event_type_on_save:
                /***********  t_base_field::field_event_type_on_delete ***********/
                case t_base_field::field_event_type_on_delete:
					if (!$a_content_loader_result->succeeded)
					{
						$a_content_loader_result->add_function_result(
							'window.cuteengine.'.$this->name,"","",
                            $this->get_row_message_script($a_row,self::style_name_err)
							.$local_error_msg);
					}
					else if (($parent_event_type == t_base_field::field_event_type_on_edit) && ($this->no_reload_on_edit))
					{
						$a_content_loader_result->add_function_result(
							'window.cuteengine.'.$this->name,"","",
							$this->get_row_message_script($a_row,self::style_name_ok).
							"this.edit_row_activation(false,true,".$a_row.");".
                            "this.clear_err_msg();");
					}
					else
					{
						$a_content_loader_result->add_function_result(
							'window.cuteengine.'.$this->name,$local_reload_event->event_name,
							t_base_field::field_event_type_on_reload.",'reload',window.cuteengine.html_tag('". $this->name ."_paging_from'),window.cuteengine.html_tag('". $this->name ."_paging_length')", '');
					}
				break;
                /***********  t_base_field::field_event_type_on_paging ***********/
                case t_base_field::field_event_type_on_paging:
					if (!$a_content_loader_result->succeeded)
					{
						$a_content_loader_result->add_function_result(
							'window.cuteengine.'.$this->name,"","",
							get_row_message_script($a_row,self::style_name_loading).
                            $local_error_msg);
					}
					else
					{
						$a_content_loader_result->add_function_result(
							'window.cuteengine.'.$this->name,$local_reload_event->event_name,"", '');
					}
                break;
            }
			
		}        
      
		
        public function get_tags_structure($a_query_parameter,$a_current_row_no,
            $a_rows_count,$a_array_param)
		{
			//echo "a_query_parameter->function_result: " .$a_query_parameter->function_result."<br>";
            $local_header_script = '';
            $local_body_script = '';
           // $local_navigator_script = '';
            if (($a_current_row_no == 0) || ($a_current_row_no == -1))
			{
                /*$this->header_script = '';
                $this->body_script = '';
                $this->navigator_script = '';*/

                $local_header_script = $a_query_parameter->execute_function_from_fields_result($this,
                    'get_header_tags_structure_'.$this->type,$this);
                //echo "local_header_script: $local_header_script<br>";
				$a_query_parameter->function_result = $local_header_script; 
                //print_r($local_header_script[0]);    
			}  
            $local_body_script = $a_query_parameter->execute_function_from_fields_result($this,
                    'get_rows_tags_structure_'.$this->type,$this);
            
            
			if ($a_current_row_no == ($a_rows_count-1))
			{
                
                $this->navigator_tag->set_text_to_include(
                    $this->get_navigator_tags_structure($a_array_param[0],$a_array_param[1]));
				
                $this->table_tag->set_text_to_include(
                    $a_query_parameter->function_result.$local_body_script); 
				//echo "a_query_parameter->function_result: " .$a_query_parameter->function_result.$local_body_script."<br>";	
			}
            else
            {
                //echo $local_header_script . $local_body_script . $local_navigator_script."<br>";
                $a_query_parameter->function_result .=  $local_body_script;
                //return $this->parent_component->main_tag->generate_html_code();
            }    
		}
		
        public function get_tags_structure_from_event($a_query_parameter,$a_current_row_no,
            $a_rows_count,$a_array_param)
		{
			$local_content_loader_result = $a_array_param[0];
			
			if (($a_current_row_no == 0) ||($a_current_row_no == -1))
			{
                $local_header_tags_structure_script = $a_query_parameter->execute_function_from_fields_result($this,
                    'get_header_tags_structure_'.$this->type,$this);
				$a_query_parameter->function_result = 
                   $this->error_msg_tag->get_start_tag_script() .
                   $this->error_msg_tag->generate_html_code().
                   $this->error_msg_tag->get_end_tag_script();
				  //echo 1; 
				$local_multi_action_form_tag_html_code = '';
                if ($this->is_multi_action_form_active() )
					$local_multi_action_form_tag_html_code = $this->multi_action_form_tag->generate_html_code();
                $a_query_parameter->function_result .=
                    $this->navigator_tag->get_start_tag_script().
                    $this->get_navigator_tags_structure($a_array_param[1],$a_array_param[2]).
					$local_multi_action_form_tag_html_code.
                    $this->navigator_tag->get_end_tag_script();  
                 // echo 2;  
                $a_query_parameter->function_result .=            
                    $this->table_tag->get_start_tag_script() .
                    $local_header_tags_structure_script;			
					//echo 3;
            }  
             //echo "a_current_row_no: $a_current_row_no <br>";          
            
            
			if ($a_current_row_no == ($a_rows_count-1))
			{
                $a_query_parameter->function_result .=
                    $a_query_parameter->execute_function_from_fields_result($this,
                    'get_rows_tags_structure_'.$this->type,$this).
                    $this->table_tag->get_end_tag_script();
                //echo "a_query_parameter->function_result: $a_query_parameter->function_result";
                
 
                /*$local_content_loader_result->add_function_result(
                    "","","",
                    "window.cuteengine.html_tag('".$this->navigator_tag->name."').innerHTML = '" .            
                    str_replace("'", "\'",$this->navigator_tag->get_start_tag_script()).
                    str_replace("'", "\'",$this->get_navigator_tags_structure($a_array_param[1],$a_array_param[2])).
                    str_replace("'", "\'",$this->navigator_tag->get_end_tag_script())."'"); */
                $local_content_loader_result->add_function_result(
                    "","","",
                    "window.cuteengine.html_tag('".$this->main_tag->name."').innerHTML = '" .            
                    str_replace("'", "\'",str_replace("\\", "\\\\", $a_query_parameter->function_result))."'");     
			}
            else            
            {
                $a_query_parameter->function_result .=           
                    $a_query_parameter->execute_function_from_fields_result($this,
                    'get_rows_tags_structure_'.$this->type,$this); 
            
            }
		}
		// I

		//gets javascript code for executing of event action 
		public function initialize_field_event($a_event_type)
        {			
			global $g_javascript_namespace;
            global $g_strings_utility_namespace;
			$local_event = $this->events[$a_event_type];
			//javascript initialization
			
			switch ($local_event->event_type) 
            {
                /***********  t_base_field::field_event_type_on_selected  ***********/
                case t_base_field::field_event_type_on_selected:

					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),'get_keys_value','a_all',"
	if (a_all)
	{
		return '[]';
	}
	else
	{
		var local_col_ind = 0;
		var local_exit = false;
		var local_result = '';
		while (!local_exit)
		{
			var local_col =  this.html_tag(this.get_tag_name('".t_field_grid::tag_prefix_row_selected."','',[local_col_ind]));
			local_exit = (local_col == null);
			if (!local_exit)
			{
				if (local_col.checked)
				{
					if (local_result == '')  
						local_result += '[\"' + local_col.keyid + '\"';
					else    
						local_result += ',\"' + local_col.keyid + '\"';
				}
				local_col_ind++;				
			}
			else
			{
				if (local_result != '')
					local_result = local_result += ']';
			}
		}
		return local_result;
	}
	");

				
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'event,a_key',"
	var local_target = event.target ? event.target : event.srcElement;
    var local_action_name = this.events_list[$a_event_type];  
	if (local_target.checked)
		local_target.parentNode.className = '".$this->name."_event_type_on_selected_checked';
	else
		local_target.parentNode.className = '".$this->name."_event_type_on_selected';
	local_target.keyid = a_key;	
    ".
						$local_event->body_code);
				break; 
                /***********  t_base_field::field_event_type_on_edit  ***********/                
				case t_base_field::field_event_type_on_edit:
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'event,a_row',"
	this.clear_err_msg();
	".$this->get_row_message_script('a_row',self::style_name_none)."
	this.edit_row_activation(true,true,a_row);
	".$local_event->body_code);
				break;
                /***********  t_base_field::field_event_type_on_cancel  ***********/  
				case t_base_field::field_event_type_on_cancel:
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'event,a_row,a_cancel_msg',"
	if (a_cancel_msg == true)
		".$this->get_row_message_script('a_row',self::style_name_none)."					
	set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_edit."','',[a_row]),(a_row != 'ins'));
    set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_insert."','',[a_row]),(a_row != 'ins'));
	set_tag_style_property(['display'],['none'],this.get_tag_name('".self::tag_prefix_row_cancel."','',[a_row]),true);
	set_tag_style_property(['display'],['none'],this.get_tag_name('".self::tag_prefix_row_save."','',[a_row]),true);	
	//var local_format_str = '".self::tag_prefix_column."';
	this.edit_row_activation(false,false,a_row);".	
	$local_event->body_code);
				break;   
				case t_base_field::field_event_type_on_save:
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'event,a_row',"
    var confRet = window.confirm (\"".$this->lang[self::language_position_question_on_execute]."\");
    if (!confRet) 
		exit;
	".$this->get_row_message_script('a_row',self::style_name_loading)."
	var local_keys = '';
	if (a_row == '".self::row_action_name_MUACT."')
	{
		var local_radio = this.html_tag('".$this->main_tag->name."_m_a_o_all'); ;
		local_keys = this.get_keys_value(local_radio.checked);
		if ((!local_radio.checked) && (local_keys == ''))
		{
			".$this->get_row_message_script('a_row',self::style_name_none)."
			return false;
		}
	}
    var local_col_num=0;
    var local_col=this.get_col_value(local_col_num);
	var local_exit = false;
	var local_argoument = '';
	var local_previous_field = null;
	while (!local_exit)
	{
        var local_tag_name = this.get_tag_name('".self::tag_prefix_value_edit."','',[a_row,local_col]);
		var local_exit = this.html_tag(local_tag_name);
		var local_field = ".t_cuteengine::javascript_instance_name."[this.get_tag_name('".self::tag_prefix_value_edit."','',['all',local_col])];
		var local_m_a_tag =  this.html_tag(this.get_tag_name('".t_field_grid::tag_prefix_value_edit."','',['filter_check',local_col]));
		if ((local_field != undefined) && 
			((a_row != '".self::row_action_name_MUACT."') || (local_m_a_tag == undefined) || (local_m_a_tag.checked)) &&
			(local_field.check_value != undefined) && (!local_field.check_value(local_tag_name))) 
        {
            ".$this->get_row_message_script('a_row',self::style_name_err)."
			return false;
        }    
		if (local_exit)
		{
            if ((local_exit.tagName == 'INPUT') && (local_exit.type == 'checkbox'))
				var local_value = local_exit.checked ? '1' : '0';
			else if (local_exit.tagName == 'A')
				var local_value = local_exit.innerHTML;
			else if (local_exit.tagName == 'IMG')
				var local_value = local_exit.previousSibling.value;	
			else
				var local_value = local_exit.value;
            if ((local_field != undefined) && (local_field.get_prepared_value != undefined))
                local_value = local_field.get_prepared_value(local_tag_name);
			if (a_row == '".self::row_action_name_MUACT."')
			{
				if (this.m_a_col == local_col_num)
					local_value = local_keys;
				else 
				{
					if ((local_m_a_tag.checked) && (local_field instanceof t_field_lookup_class))
					{
						var local_tmp_array = local_argoument.split('|');
						local_tmp_array[local_tmp_array.length-1] = local_tmp_array[local_tmp_array.length-1].replace('false','true');
						local_argoument = local_tmp_array.join('|');
					}
						
					local_value = '[\"'+local_m_a_tag.checked+'\",\"'+local_value+'\"]';
				}
			}	
				
				
				
			".$g_strings_utility_namespace->get_javascript_code_to_hide_separetor("local_col","local_argoument","local_value")."
            var local_source = local_exit;	
            local_exit = false;
		}		
		else
		  local_exit = true;
		local_col_num ++;
        local_col=this.get_col_value(local_col_num);
		local_previous_field = local_field;
	}
	
	if (a_row == 'ins')
		var local_event_type = ".t_base_field::field_event_type_on_insert.";
	else if (a_row == '".self::row_action_name_MUACT."')
		var local_event_type = ".t_base_field::field_event_type_on_edit.";
	else
		var local_event_type = ".t_base_field::field_event_type_on_edit.";
    var local_action_name = this.events_list[$a_event_type];   
    if (local_argoument != '')
        local_argoument = '".t_url_parameter::separator_level_0 . "' + local_event_type +'".t_url_parameter::separator_level_0."' + a_row + local_argoument; 
    ".	$local_event->body_code);
				break;    
				/***********  t_base_field::field_event_type_on_insert  ***********/                
				case t_base_field::field_event_type_on_insert:
                    
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'event,a_row',"
	this.clear_err_msg();
	".$this->get_row_message_script('a_row',self::style_name_none)."
	this.edit_row_activation(true,true,a_row);
	".$local_event->body_code);
    
    /*.$this->get_row_message_script("'ins'",self::style_name_none)."					
	set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_cancel."','',[a_row]),true);
	set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_row_save."','',[a_row]),true);	
    //var local_format_str = '".self::tag_prefix_column."';
	var local_col_num=0;
    var local_col=this.get_col_value(local_col_num);
	var local_found = true;
	while (local_found)
	{
		local_found = set_tag_style_property(['display'],['none'],this.get_tag_name('".self::tag_prefix_value."','',[a_row,local_col]),true);
		if (local_found)
		{
			local_found =set_tag_style_property(['display'],[''],this.get_tag_name('".self::tag_prefix_value_edit."','',[a_row,local_col]));
			if (local_found)
			{
				local_found.value = '';
			}	
		}
		local_col_num ++;
        local_col=this.get_col_value(local_col_num);
	}".	$local_event->body_code);*/
				break;
				/***********  t_base_field::field_event_type_on_paging  ***********/  				
				case t_base_field::field_event_type_on_paging:
                    //echo "field_event_type_on_paging field_name:".$this->name."<br>";
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'a_event_type,a_paging_type,a_from,a_length',"
	var local_from = 0;
    if (a_from != undefined)
        local_from = parseInt(a_from.value);
	var local_length = 0;
    if (a_length != undefined)
        local_length = parseInt(a_length.value);
	if (a_event_type == ".t_base_field::field_event_type_on_paging.")
		if (a_paging_type == 'previous')
			local_from = local_from - local_length;
		else if (a_paging_type == 'next')
			local_from = local_from + local_length;
	
	var local_action_name = this.events_list[a_event_type];		
	local_argoument = '".t_url_parameter::separator_level_0 . "' + a_event_type +'".t_url_parameter::separator_level_0."' + local_from +'".t_url_parameter::separator_level_0."' + local_length;
	");
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'a_event_type,a_paging_type,a_from,a_length',"
	if (local_action_name == '".$this->parent_part->get_call_back_action_hashed_name($a_event_type)."')
    {
        ".	$local_event->body_code."
    }");    

				break;                
                /***********  t_base_field::field_event_type_on_reload  ***********/       
				case t_base_field::field_event_type_on_reload:
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'a_event_type,a_paging_type,a_from,a_length',"
	var local_from = 0;
    if (a_from != undefined)
        local_from = parseInt(a_from.value);
	var local_length = 0;
    if (a_length != undefined)
        local_length = parseInt(a_length.value);
	
	var local_action_name = this.events_list[a_event_type];		
	local_argoument = '".t_url_parameter::separator_level_0 . "' + a_event_type +'".t_url_parameter::separator_level_0."' + local_from +'".t_url_parameter::separator_level_0."' + local_length;
	");
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'a_event_type,a_paging_type,a_from,a_length',"
	if (local_action_name == '".$this->parent_part->get_call_back_action_hashed_name($a_event_type)."')
    {
        ".	$local_event->body_code."
    }");    
				break;                
				/***********  t_base_field::field_event_type_on_delete  ***********/                
				case t_base_field::field_event_type_on_delete:
                    
					$g_javascript_namespace->header_script_generator->add_method_to_a_class_with_content(
						get_class($this),$local_event->event_name,'event,a_row',"
    var confRet = window.confirm (\"".$this->lang[self::language_position_question_on_delete]."\");
    if (confRet) 
    {
		".$this->get_row_message_script('a_row',self::style_name_loading)."
		var local_keys = '';
		var local_argoument = '';
		var local_action_name = this.events_list[$a_event_type];
		if (a_row == '".self::row_action_name_MUACT."')
		{
			var local_radio = this.html_tag('".$this->main_tag->name."_m_a_o_all'); ;
			local_keys = this.get_keys_value(local_radio.checked);
			if ((!local_radio.checked) && (local_keys == ''))
			{
				".$this->get_row_message_script('a_row',self::style_name_none)."
				return false;
			}
			local_argoument += '@' + hide_separator(local_keys);
		}
		else
		{
			 
			".$this->get_row_message_script('a_row',self::style_name_loading)."
			var local_col_num=0;
			var local_col=this.get_col_value(local_col_num);
			var local_exit = false;
			
			while (!local_exit)
			{
				var local_exit = this.html_tag(this.get_tag_name('".self::tag_prefix_value."','',[a_row,local_col]));
				if (local_exit)
				{
					var local_source = local_exit;		
					local_exit = false;
					".$g_strings_utility_namespace->get_javascript_code_to_hide_separetor("local_col_num","local_argoument","local_source.innerHTML")."
				}		
				else
				  local_exit = true;
				local_col_num ++;
				local_col=this.get_col_value(local_col_num);
			}
		}
		var local_event_type = ".t_base_field::field_event_type_on_delete.";
		
		if (local_argoument != '')
			local_argoument = '".t_url_parameter::separator_level_0 . "' + local_event_type +'".t_url_parameter::separator_level_0."' + a_row + local_argoument;
        ".	$local_event->body_code ."
    }");
				break;                
			}	
            
		}
		public function is_db_field_to_be_check($a_index)
		{
			$local_column_definition = $this->special_columns_array[$a_index];
			//echo "local_column_definition[self::special_column_parameters_column_field_type]: ". $local_column_definition[self::special_column_parameters_column_field_type]."<br>";
			return (($local_column_definition[self::special_column_parameters_column_field_type] != self::special_column_type_hidden_column) &&
					($local_column_definition[self::special_column_parameters_column_field_type] != self::special_column_type_no_edit_column) &&
					($local_column_definition[self::special_column_parameters_column_field_type] != self::special_column_type_column_url_parameter_value) &&
					($local_column_definition[self::special_column_parameters_column_field_type] != t_field_do_it));
		}
		public function is_multi_action_form_active()
		{
			//echo "this->proper_properties_array[self::proper_properties_position_per_multi_action_form]: ".$this->proper_properties_array[self::proper_properties_position_per_multi_action_form];
			return ((strtoupper($this->proper_properties_array[self::proper_properties_position_per_multi_action_form]) === 'TRUE') || 
			($this->proper_properties_array[self::proper_properties_position_per_multi_action_form] === 1)|| 
			($this->proper_properties_array[self::proper_properties_position_per_multi_action_form] === true));
		}
		
		
		public function set_multi_action_script($a_special_column,$a_current_field_no,$a_query_parameter,$a_current_field,$a_is_primary_key_column)
		{
			global $g_javascript_namespace;
			if ($this->is_multi_action_form_active())
			{
				
				if ($a_is_primary_key_column)
				{
					
					$g_javascript_namespace->header_script_generator->add_content_to_a_method(get_class($this),
						t_header_script_generator::create_label,"
		if (this.name == '".$this->name."')
			this.m_a_col = $a_current_field_no;
		");
				}
				if ((isset($a_special_column)) && 
					(($a_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_hidden_column) ||
					($a_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_column_title_hide)||
					($a_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_no_edit_column)||
					(($a_special_column[t_field_grid::special_column_parameters_column_field_type] == t_field_grid::special_column_type_column_url_parameter_value) && (strtoupper($this->get_special_column_type_parameter_value($a_current_field_no,2)) !== 'TRUE'))))
				{
					$local_style = 'style="display: none"';
					$local_div_style = 'style="display: none"';
					$local_tags = "<input disabled=\"disabled\" class= \"".$this->name."_filter_field_class\" $local_style id=\"". 
					$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('MUACT',$this->get_col_value($a_current_field_no))) .
						"\" ></input>";
					
				}    
				else 
				{
					$local_tags = '';
					if (isset($a_special_column))
					{
						if ($a_special_column[t_field_grid::special_column_parameters_column_description_number] == $a_current_field_no)
						{
							$local_field = $this->parent_part->get_field($this->get_special_column_field('all',$a_special_column[t_field_grid::special_column_parameters_column_description]));
							if (isset($local_field))
							{
								$local_div_style = '';
								//echo "IT IS SPECIAL COLUMN a_current_field_no:$a_current_field_no<br>";
								//if ($this->is_id_field_required($a_special_column[t_field_grid::special_column_parameters_column_field_type]))
								$local_key_col_num = $a_special_column[t_field_grid::special_column_parameters_column_id_number];
								//else
								$local_col_num = $a_special_column[t_field_grid::special_column_parameters_column_description_number];
								$local_tags = $local_field->get_included_in_html_structure(
									$this->get_special_column_field('MUACT',$a_special_column[t_field_grid::special_column_parameters_column_description]),
									false,$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('MUACT',$this->get_col_value($local_key_col_num))),
									'MUACT');
								//echo "local_tags: $local_tags<br>";
							}
						}
						else
						{
							$local_style = 'style="display: none"';
							$local_div_style = 'style="display: none"';
							$local_tags = "<input disabled=\"disabled\" class= \"".$this->name."_filter_field_class\" $local_style id=\"". 
							$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('MUACT',$this->get_col_value($a_current_field_no))) .
								"\" ></input>";
						}
					}
					else
					{
						$local_div_style = '';
						$local_style = 'style="display: none"';
						$local_tags = "<input class= \"".$this->name."_filter_field_class\" $local_style id=\"". 
						$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('MUACT',$this->get_col_value($a_current_field_no))) .
						"\" ></input>";
					}
					//$local_filter_script =	$local_tags;
					
				}		
				if ($local_tags != '')
					$local_filter_script = "<div $local_div_style id=\"".$this->name."_filtered_div\" class= \"".$this->name."_filter_div_class\">".
						"<input id=\"".$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('filter_check',$this->get_col_value($a_current_field_no))) .
						"\" type=\"checkbox\" onclick=\"".t_cuteengine::javascript_instance_name.".".$this->name.".enable_field_edit(event,'".self::row_action_name_MUACT."','".$this->get_col_value($a_current_field_no)."')\" value=\"enabled\" ".$this->get_field_event_script(t_base_field::field_event_type_on_selected,"event,'".$a_query_parameter->sql_values[$a_current_field_no]."'")."/>".
						"<label class= \"".$this->name."_filter_lbl\" id=\"".$this->get_tag_name(t_field_grid::tag_prefix_value_edit,array('filter_lbl',$this->get_col_value($a_current_field_no))) .
						"\">$a_current_field->name</label>".$local_tags."</div>";

				if ($a_current_field_no == 0)	
					$this->multi_action_form_fields_tag->set_text_to_include("<a><image id=\"". $this->get_tag_name(t_field_grid::tag_prefix_row_message,array(self::row_action_name_MUACT)) ."\" class=\"".$this->get_tag_name(t_field_grid::style_name_none,array($this->name))."\"></image></a>".$local_filter_script);
				else
					$this->multi_action_form_fields_tag->add_text_to_include($local_filter_script);
			}	
		}
    }
?>    